Do not assume that text is null-terminated as pointed out by Christopher
authorJohan Dahlin <jdahlin@async.com.br>
Tue, 7 Aug 2007 21:52:29 +0000 (21:52 +0000)
committerJohan Dahlin <johan@src.gnome.org>
Tue, 7 Aug 2007 21:52:29 +0000 (21:52 +0000)
2007-08-07  Johan Dahlin  <jdahlin@async.com.br>

    * gtk/gtkbuilderparser.c (text):
    * gtk/gtkcelllayout.c (attributes_text_element):
    * gtk/gtkliststore.c (list_store_text):
    Do not assume that text is null-terminated as pointed out by
    Christopher Fergeau

svn path=/trunk/; revision=18592

ChangeLog
gtk/gtkbuilderparser.c
gtk/gtkcelllayout.c
gtk/gtkliststore.c

index 27c57a874b29a6c2292360764d2ee3a791123abc..327018863bb989f6680e78249adeeccae02ae0f7 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2007-08-07  Johan Dahlin  <jdahlin@async.com.br>
 
+       * gtk/gtkbuilderparser.c (text): 
+       * gtk/gtkcelllayout.c (attributes_text_element): 
+       * gtk/gtkliststore.c (list_store_text): 
+       Do not assume that text is null-terminated as pointed out by
+       Christopher Fergeau
+       
        * gtk/gtkbuilderparser.c (text): Use g_strdup on the translated
        string instead of g_strndup() + the length of the untranslated
        string. (#461945, Claude Paroz)
index 9ca1889b47b371f17ae8ad4dba482b0bef6d46e5..23d45db4791f579112c829525882d678fdc805f5 100644 (file)
@@ -908,14 +908,20 @@ text (GMarkupParseContext *context,
     {
       PropertyInfo *prop_info = (PropertyInfo*)info;
 
+      /* text is not guaranteed to be null-terminated */
+      char *string = g_strndup (text, text_len);
+
       if (prop_info->translatable && text_len)
         {
-          if (prop_info->context)
-            text = dpgettext (data->domain, prop_info->context, text);
+         if (prop_info->context)
+            text = dpgettext (data->domain, prop_info->context, string);
           else
-            text = dgettext (data->domain, text);
+            text = dgettext (data->domain, string);
+
+         g_free (string);
+         string = g_strdup (text);
         }
-      prop_info->data = g_strdup (text);
+      prop_info->data = string;
     }
 }
 
index 970ec954df5ec3139f4b9eb1395f0c682534611e..a9b1c6f6c04728bc0d646c1721cf398cca549816 100644 (file)
@@ -349,21 +349,25 @@ attributes_text_element (GMarkupParseContext *context,
   AttributesSubParserData *parser_data = (AttributesSubParserData*)user_data;
   glong l;
   gchar *endptr;
-
+  gchar *string;
+  
   if (!parser_data->attr_name)
     return;
 
   errno = 0;
-  l = strtol (text, &endptr, 0);
-  if (errno || endptr == text)
+  string = g_strndup (text, text_len);
+  l = strtol (string, &endptr, 0);
+  if (errno || endptr == string)
     {
       g_set_error (error, 
                    GTK_BUILDER_ERROR,
                    GTK_BUILDER_ERROR_INVALID_VALUE,
                    "Could not parse integer `%s'",
-                   text);
+                   string);
+      g_free (string);
       return;
     }
+  g_free (string);
 
   gtk_cell_layout_add_attribute (parser_data->cell_layout,
                                 parser_data->renderer,
index 5694f7640032376f424750270950751e3abb01b2..617a5fedd8adaeb76a9e7c567d19ed10eb4bccf6 100644 (file)
@@ -2188,15 +2188,17 @@ list_store_text (GMarkupParseContext *context,
   SubParserData *data = (SubParserData*)user_data;
   gint i;
   GError *tmp_error = NULL;
+  gchar *string;
   
   if (!data->is_data)
     return;
 
   i = data->row_column - 1;
 
+  string = g_strndup (text, text_len);
   if (!gtk_builder_value_from_string_type (data->builder,
                                           data->column_types[i],
-                                          text,
+                                          string,
                                           &data->values[i],
                                           &tmp_error))
     {
@@ -2208,6 +2210,7 @@ list_store_text (GMarkupParseContext *context,
                   tmp_error->message);
       g_error_free (tmp_error);
     }
+  g_free (string);
 }
 
 static const GMarkupParser list_store_parser =